namespace Trader.Analyzing
{
    using Interface;

    public class Range : IRange
    {
        private readonly decimal lowerBounds;
        private readonly decimal upperBounds;

        public Range(decimal lowerBounds, decimal upperBounds)
        {
            this.lowerBounds = lowerBounds;
            this.upperBounds = upperBounds;
        }

        #region IRange Members

        public bool IsInRange(decimal value)
        {
            return lowerBounds <= value && value <= upperBounds;
        }

        public decimal Mid
        {
            get { return Average(lowerBounds, upperBounds); }
        }

        public int CompareTo(IRange other)
        {
            return Mid.CompareTo(other.Mid);
        }

        #endregion

        private static decimal Average(decimal numOne, decimal numTwo)
        {
            return (numOne + numTwo)/2;
        }
    }
}